require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsArenaBoxHandler ={};
local this = RedDotsArenaBoxHandler;

local arenaRewardConfig;

function RedDotsArenaBoxHandler.init()
    CloseEvent(Config.EventType.Fresh_Arena,this.update);
    ListenEvent(Config.EventType.Fresh_Arena,this.update);

    if arenaRewardConfig == nil then
        arenaRewardConfig = G.dataTable["t_arenaboxreward"];
    end
    return this;
end


--参数 boxId :宝箱ID int类型参数,nil代表检查所有宝箱
function RedDotsArenaBoxHandler.getFlag(...)
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Arena,false) then
        local arenaBaseoInfo = logicMgr.ArenaManager.getBaseInfo();
        local boxId = ...;
        if boxId~=nil then
            local boxCofig = arenaRewardConfig[tostring(boxId)]
            if boxCofig~=nil and arenaBaseoInfo.winCount>=boxCofig.f_winCount and not logicMgr.ArenaManager.IsGetReward(boxId) then
                return Config.RedDotsFlagState.Needful;
            end
        else
            for key, value in pairs(arenaRewardConfig) do
                if arenaBaseoInfo.winCount>=value.f_winCount  and not logicMgr.ArenaManager.IsGetReward(value.f_Id) then
                    return Config.RedDotsFlagState.Needful;
                end
            end
        end
    end
    return Config.RedDotsFlagState.None;
end


function RedDotsArenaBoxHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.ArenaBox);
end